﻿using phones.Repository;
using phones.Model;
using phones.ViewModel.TreeViewModel;

namespace phones.ViewModel
{
    public class DepartnemtNodeTreeItemViewModel: TreeViewItemBaseViewModel
    {

        private Department _department;

        public Department Model
        {
            get { return _department; }
        }

        public DepartnemtNodeTreeItemViewModel(OrganisationNodeTreeItemViewModel parent, Department dep)
            : base(parent, true)
        {
            _department = dep;
        }

        protected override void LoadChildren()
        {
            Children.Clear();

            var db = new ContactsRepository();
            var list = db.GetList((Parent.Parent as ServiceNodeTreeItemViewModel).Model, _department);

            foreach (var item in list)
            {
                 Children.Add(new ContactTreeItemViewModel(this,item));
            }
        }

    }
}
